<%@page import="com.zhiyou.entities.User"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style type="text/css">
div{width:500px;}

</style>
<script type="text/javascript">
   function deleteUser(id){
	   window.location.href="doDeleteUser.jsp?id="+id;
   }
   function getfocus(){
		//清空内容
		var searchCondition =document.getElementById("searchCondition");
		if(searchCondition.value=="输入id或者用户名"){
			searchCondition.value="";
		}
	}
   function losefocus(){
		var searchCondition =document.getElementById("searchCondition");
		if(searchCondition.value==""){
			searchCondition.value="输入id或者用户名";
		}
	}
</script>
</head>
<body>
<!-- 此案例稍微修改就是租房网 -->
<!-- 查看所有用户 -->
<!-- 登录成功后，直接显示所有用户 -->
<div>
<%
	request.setCharacterEncoding("utf-8");
	response.setCharacterEncoding("utf-8");
	if((Integer)session.getAttribute("userRole")>0){
%>
    <div align="left"><a href="addUser.jsp"><button>新增</button></a></div>
    
    <div>
 	<form action="doSearch.jsp" method="get">
 	  <input type="text" name="searchCondition" id="searchCondition" value="输入id或者用户名" onfocus="getfocus()" onblur="losefocus()"/>
 	  <button type="submit">查询</button>
 	</form>
 </div>
   
<%		
	}
%>
 

<%
List<User> list=(List<User>)session.getAttribute("list");
%>
<table>
 <tr>
   <td>id</td><td>用户名</td>
   <td>密码</td><td>删除</td>
 </tr>
 <%
 for(int i=0; i<list.size();i++){
	
%>
	 <tr>
		 <td><a href="dogetUserById.jsp?id=<%=list.get(i).getId() %>"><%=list.get(i).getId() %></a></td>
		 <td><%=list.get(i).getUsername() %></td>
		 <td><%=list.get(i).getPwd() %></td>
		 <td><button onclick="deleteUser(<%=list.get(i).getId() %>)">删除</button></td>
	 </tr>
<%
 }
 %>
 
</table>

</div>

</body>
</html>